<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryParams" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="主题" prop="cmTitle">
        <el-input v-model="queryParams.cmTitle" placeholder="请输入班会主题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="内容" prop="cmTheme">
        <el-input v-model="queryParams.cmTextContent" placeholder="请输入班会主题" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开始时间" prop="cmStart">
        <el-date-picker clearable v-model="queryParams.cmStart" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择计划开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="cmEnd">
        <el-date-picker clearable v-model="queryParams.cmEnd" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择班会计划结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['runtine:ClassMettingTheme:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ClassMettingThemeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编码" align="center" prop="cmId" v-if="false" />
      <el-table-column label="班会标题" align="center" prop="cmTitle" :show-overflow-tooltip="true" />
      <el-table-column label="主题内容" align="center" prop="cmTextTheme" :show-overflow-tooltip="true" />
      <el-table-column label="是否需要上传材料" align="center" prop="cmIsupload" :formatter="setYesOn" />
      <el-table-column label="是否已上传" align="center" prop="isComplate" :formatter="setYesOn" />
      <el-table-column label="班会分类" align="center" prop="cmProp">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rt_cm_type" :value="scope.row.cmProp" />
        </template>
      </el-table-column>
      <el-table-column label="班会计划开始时间" align="center" prop="cmStart" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cmStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="班会计划结束时间" align="center" prop="cmEnd" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cmEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" :formatter="getStatusName" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">上传附件</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleOpenDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog :title="title" :visible.sync="detailOpen" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="200px">

        <el-form-item label="班会标题" prop="cmTitle">
          <el-input v-model="form.cmTitle" placeholder="请输入班会标题" disabled />
        </el-form-item>
        <el-form-item label="主题内容" prop="cmTheme">
          <div v-html="form.cmTheme"></div>
        </el-form-item>
        <el-form-item label="是否需要上传材料" prop="cmIsupload" disabled>
          <el-select v-model="form.cmIsupload" placeholder="请选择否需要上传材料" disabled>
            <el-option label="否" value="0"></el-option>
            <el-option label="是" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班会分类" prop="cmProp" disabled>
          <el-select v-model="form.cmProp" placeholder="" disabled>
            <el-option v-for="dict in dict.type.rt_cm_type" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="班会计划开始时间" prop="cmStart">
          <el-date-picker clearable disabled v-model="form.cmStart" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择班会计划开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="班会计划结束时间" prop="cmEnd">
          <el-date-picker clearable disabled v-model="form.cmEnd" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择班会计划结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="附件">
          <AttachUpload :fileListPut="tmpResList" :isShowBtn="false" :isShowTip="false"></AttachUpload>
        </el-form-item>
        <el-form-item label="备注" prop="remark" disabled>
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" disabled />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="上传附件" :fullscreen="true" :visible.sync="uploadV" append-to-body>
      <Content v-if="uploadV"/>
    </el-dialog>

  </div>
</template>

<script>
import { listClassMettingTheme, getClassMettingTheme, listClassMettingComplateTheme } from "@/api/routine/theme/ClassMettingTheme";
import AttachUpload from "@/components/AttachUpload";

import Content from "@/views/routine/classmetting/content/index.vue"

export default {
  name: "ClassMettingTheme",
  dicts: ['rt_cm_type'],
  components: { AttachUpload, Content },
  data() {
    return {

      uploadV: false,

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      tmpResList: [],
      // 总条数
      total: 0,
      // 班会主题表格数据
      ClassMettingThemeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //详情弹出层
      detailOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cmNo: null,
        cmTheme: null,
        cmTitle: null,
        cmIsupload: null,
        cmProp: null,
        cmStart: null,
        cmEnd: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询班会主题列表 */
    getList() {
      this.loading = true;
      listClassMettingComplateTheme(this.queryParams).then(response => {
        this.ClassMettingThemeList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.resetForm("queryForm");
      });
    },
    //是否转换
    setYesOn(row, column) {
      let label = "否";
      if (column.property == "cmIsupload") {
        if (row.isComplate)
          if (row.cmIsupload == 1) {
            label = "是";
          }
      } else if (column.property == "isComplate") {
        if (row.cmIsupload)
          if (row.isComplate == 1) {
            label = "是";
          }
      }
      return label;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cmId: null,
        cmNo: null,
        cmTheme: null,
        cmTitle: null,
        cmIsupload: null,
        attachResourceList: null,
        cmProp: null,
        cmStart: null,
        cmEnd: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cmId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加班会主题";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const cmNo = row.cmNo;
      this.$store.cmNo = cmNo;
      this.uploadV = true;
      //this.$router.push({ path: "/routine/classmeting/mettingresource", query: { cmNo: cmNo } });
    },
    handleOpenDetail(row) {
      this.reset();
      const cmId = row.cmId;
      getClassMettingTheme(cmId).then(response => {
        this.form = response.data;
        let tmpurl = [];
        tmpurl = this.form.attachResourceList;
        this.tmpResList = [];
        tmpurl.forEach(item => {
          this.tmpResList.push({
            originalFileName: item.resName,
            url: item.resPath,
            name: item.resName
          })
        });
        //console.log(this.tmpResList);
        this.detailOpen = true;
        this.title = "班会主题详情";
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('runtine/ClassMettingTheme/export', {
        ...this.queryParams
      }, `ClassMettingTheme_${new Date().getTime()}.xlsx`)
    },
    getStatusName(row, column) {
      if (row.status == 0) {
        return "保存";
      }
      else if (row.status == 1) {
        return "发布";
      }
    },
  }
};
</script>